package org.dna.opdracht4;

import java.util.List;
import java.util.ArrayList;

public class Vertex<T> {
	private T value;
	private List<Edge<T>> edgeIn;
	private List<Edge<T>> edgeOut;
	private int visited = 0;
	private int earliestTime;
	private int latestTime;

	public Vertex(T value) {
		this.value = value;
		earliestTime = 0;
		latestTime = 0;
		edgeOut = new ArrayList<Edge<T>>();
		edgeIn = new ArrayList<Edge<T>>();
	}

	public Vertex(T value, int earliestTime, int latestTime) {
		this(value);
		this.earliestTime = earliestTime;
		this.latestTime = latestTime;
	}

	public T getValue() {
		return value;
	}

	public int getEarliestTime() {
		return earliestTime;
	}

	public int getLatestTime() {
		return latestTime;
	}

	public void addOutEdge(Edge<T> edge) {
		edgeOut.add(edge);
	}

	public void addInEdge(Edge<T> edge) {
		edgeIn.add(edge);
	}

	public List<Edge<T>> getOutEdges() {
		return edgeOut;
	}

	public List<Edge<T>> getInEdges() {
		return edgeIn;
	}

	public void resetVisited() {
		visited = 0;
	}

	public int getVisited() {
		return visited;
	}

	public void increaseVisited() {
		visited++;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Vertex: ");
		builder.append(" value = ");
		builder.append(value);
		builder.append(" earliestTime = ");
		builder.append(earliestTime);
		builder.append(" latestTime = ");
		builder.append(latestTime);

		return builder.toString();
	}

	public void setEarliestTime(int cost) {
		if (earliestTime < cost) {
			earliestTime = cost;
		}
	}

	public void setLatestTime(int cost) {
		if (latestTime > cost && cost >= 0) {
			latestTime = cost;
		}
		if(getVisited() == 0){
			latestTime = cost;
		}
	}
}